{
  LX Value module

  Based on modo's SDK lxvalue.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software. Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012 David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_Value;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result, Lx_VMath;

const
  LXa_VALUESERVICE         = 'valueservice';
  LXa_VALUE                = 'value'       ;
  LXa_MESSAGE              = 'message'     ;
  LXa_VALUEARRAY           = 'valuearray'  ;
  LXa_SCRIPTQUERY          = 'scriptquery' ;
  LXa_VISITOR              = 'visitor'     ;

  LXi_TYPE_OBJECT          = 0;
  LXi_TYPE_INTEGER         = 1;
  LXi_TYPE_FLOAT           = 2;
  LXi_TYPE_STRING          = 3;

  LXsTYPE_INTEGER          = 'integer'    ;
  LXsTYPE_FLOAT            = 'float'      ;
  LXsTYPE_DISTANCE         = 'distance'   ;
  LXsTYPE_PERCENT          = 'percent'    ;
  LXsTYPE_ANGLE            = 'angle'      ;
  LXsTYPE_FLOAT3           = 'float3'     ;
  LXsTYPE_DISTANCE3        = 'distance3'  ;
  LXsTYPE_PERCENT3         = 'percent3'   ;
  LXsTYPE_ANGLE3           = 'angle3'     ;
  LXsTYPE_TIME             = 'time'       ;
  LXsTYPE_LIGHT            = 'light'      ;
  LXsTYPE_STRING           = 'string'     ;
  LXsTYPE_FILEPATH         = 'filepath'   ;
  LXsTYPE_UVCOORD          = 'uvcoord'    ;
  LXsTYPE_BOOLEAN          = 'boolean'    ;
  LXsTYPE_AXIS             = 'axis'       ;
  LXsTYPE_MEMORY           = 'memory'     ;
  LXsTYPE_PIXEL            = 'pixel'      ;
  LXsTYPE_FPIXEL           = 'fpixel'     ;
  LXsTYPE_COLOR            = 'color'      ;
  LXsTYPE_COLOR1           = 'color1'     ;
  LXsTYPE_MATRIX3          = 'matrix3'    ;
  LXsTYPE_MATRIX4          = 'matrix4'    ;
  LXsTYPE_DATETIME         = 'datetime'   ;
  LXsTYPE_TOD              = 'timeofday'  ;
  LXsTYPE_DATE             = 'date'       ;
  LXsTYPE_OBJREF           = 'objref'     ;
  LXsTYPE_VERTMAPNAME      = 'vertmapname';

  LXu_VALUESERVICE         = '{DD2C3059-2CD0-4c7d-860C-CF353CFB2F92}';
  LXu_VALUE                = '{62E1DBE9-2FFE-4B5C-B286-E54E79415303}';
  LXu_STRINGCONVERSION     = '{5CB3EEDB-E4E0-499E-B0BA-A7FB51BABE3C}';
  LXu_STRINGCONVERSIONNICE = '{5407328B-DE99-4F15-866F-F6E214FFA412}';
  LXu_VALUEMATH            = '{752B4D2E-6F13-4B2C-B0B3-0BA8CA6B0692}';
  LXu_VALUEREFERENCE       = '{0567BC88-F782-426E-98C5-8302FD52D9E4}';
  LXu_ATTRIBUTES           = '{117957D0-5A13-11D7-A18C-000A95765C9E}';
  LXu_MESSAGE              = '{DDDBF46A-0865-4AB7-9962-72E7B477FD22}';
  LXu_VALUEARRAY           = '{A964962F-9028-4CA3-9612-17D360DF92BA}';
  LXu_SCRIPTQUERY          = '{0434F07E-AD4A-492f-AD43-3249BD16994D}';
  LXu_STRINGTAG            = '{C2004BC7-6A90-4BD3-BDF7-B375C790DB70}';
  LXu_MATRIX               = '{EF9FDE7B-E7FA-48B2-838E-A5A8F7D5C254}';
  LXu_VISITOR              = '{C8FCAD70-DDDF-499E-A03B-A08B906D3E53}';

type
  PPLXtTextValueHint = ^PLXtTextValueHint;
  PLXtTextValueHint  = ^LXtTextValueHint ;
  LXtTextValueHint   = record
    Value : Integer;
    Text  : PChar  ;
  end;

  ILxValueService = interface
  [LXu_VALUESERVICE]
    function ScriptQuery   (  out VObj                      ) : LxResult;
    function TextHintEncode(      Value  : Integer          ;
                            const Hint   : PLXtTextValueHint;
                                  Buf    : PChar            ;
                                  BufLen : UInt32           ) : LxResult;
    function TextHintDecode(const Buf    : PChar            ;
                            const Hint   : PLXtTextValueHint;
                                  Value  : Integer          ) : LxResult;
    function CreateValue   (const &Type  : PChar            ;
                              out VObj                      ) : LxResult;
  end;

  ILxValue = interface
  [LXu_VALUE]
    function Clone    (  out VObj            ) : LxResult;
    function Copy     (      From  : IUnknown) : LxResult;
    function Compare  (      Other : IUnknown;
                             Diff  : PInteger) : LxResult;
    function &Type                             : UInt32  ;
    function GetInt   (      Val   : PInteger) : LxResult;
    function SetInt   (      Val   : Integer ) : LxResult;
    function GetFlt   (      Val   : PDouble ) : LxResult;
    function SetFlt   (      Val   : Double  ) : LxResult;
    function GetString(      Val   : PChar   ;
                             Len   : UInt32  ) : LxResult;
    function SetString(const Val   : PChar   ) : LxResult;
    function Intrinsic                         : Pointer ;
  end;

  ILxStringConversion = interface
  [LXu_STRINGCONVERSION]
    function Encode(      Buf : PChar  ;
                          Len : Integer) : LxResult;
    function Decode(const Buf : PChar  ) : LxResult;
  end;

  ILxStringConversionNice = interface
  [LXu_STRINGCONVERSIONNICE]
    function Encode(      Buf : PChar  ;
                          Len : Integer) : LxResult;
    function Decode(const Buf : PChar  ) : LxResult;
  end;

  ILxValueMath = interface
  [LXu_VALUEMATH]
    function Step    (Direction : Integer ) : LxResult;
    function Detent                         : Integer ;
    function Add     (Delta     : Double  ) : LxResult;
    function Multiply(Factor    : Double  ) : LxResult;
    function Blend   (Other     : IUnknown;
                      Blend     : Double  ) : LxResult;
  end;

  ILxValueReference = interface
  [LXu_VALUEREFERENCE]
    function IsSet                          : LxResult;
    function GetObject(out VObj           ) : Integer ;
    function SetObject(    Obj  : IUnknown) : LxResult;
  end;

  ILxAttributes = interface
  [LXu_ATTRIBUTES]
    function Count_                               : UInt32           ;
    function Name     (      Index    : UInt32  ;
                       const Name     : PPChar  ) : LxResult         ;
    function Lookup   (const Name_    : PChar   ;
                             Index    : PUInt32 ) : LxResult         ;
    function Type_    (      Index    : UInt32  ;
                             Type__   : PUInt32 ) : LxResult         ;
    function TypeName (      Index    : UInt32  ;
                       const Name_    : PPChar  ) : LxResult         ;
    function Hints    (      Index    : UInt32  ) : PLXtTextValueHint;
    function Value    (      Index    : UInt32  ;
                         out VObj               ;
                             WriteOK  : Integer ) : Integer          ;
    function GetInt   (      Index    : UInt32  ;
                             Val      : PInteger) : LxResult         ;
    function SetInt   (      Index    : UInt32  ;
                             Val      : Integer ) : LxResult         ;
    function GetFlt   (      Index    : UInt32  ;
                             Val      : PDouble ) : LxResult         ;
    function SetFlt   (      Index    : UInt32  ;
                             Val      : Double  ) : LxResult         ;
    function GetString(      Index    : UInt32  ;
                             Val      : PChar   ;
                             Len      : UInt32  ) : LxResult         ;
    function SetString(      Index    : UInt32  ;
                       const Val      : PChar   ) : LxResult         ;
  end;

  ILxMessage = interface
  [LXu_MESSAGE]
    function Code                                            : LxResult;
    function SetCode          (      Code_       : LxResult) : LxResult;
    function SetMessage       (const Table, Name : Pchar   ;
                                     ID          : UInt32  ) : LxResult;
    function SetArgumentInt   (      Arg         : UInt32  ;
                                     Value       : Integer ) : LxResult;
    function SetArgumentFloat (      Arg         : UInt32  ;
                                     Value       : Double  ) : LxResult;
    function SetArgumentString(      Arg         : UInt32  ;
                                     String_     : PChar   ) : LxResult;
    function SetArgumentObject(      Arg         : UInt32  ;
                                     Object_     : IUnknown) : LxResult;
    function Reset                                           : LxResult;
    function Table            (const Table       : PPChar  ) : LxResult;
    function Name             (const Name        : PPChar  ) : LxResult;
    function SetMessageResult (      ID          : UInt32  ) : LxResult;
  end;

  ILxValueArray = interface
  [LXu_VALUEARRAY]
    function &Type        (      &Type       : PUInt32 ) : LxResult;
    function TypeName     (const Name        : PPChar  ) : LxResult;
    function Count                                       : UInt32  ;
    function AddEmptyValue(  out VObj                  ) : LxResult;
    function AddValue     (      Value       : IUnknown) : LxResult;
    function AddInt       (      Value       : integer ) : LxResult;
    function AddFloat     (      Value       : Double  ) : LxResult;
    function AddString    (const Value       : PChar   ) : LxResult;
    function GetValue     (      Index       : UInt32  ;
                             out VObj                  ) : LxResult;
    function GetInt       (      Index       : UInt32  ;
                                 Value       : PUInt32 ) : LxResult;
    function GetFloat     (      Index       : UInt32  ;
                                 Value       : PDouble ) : LxResult;
    function GetString    (      Index       : UInt32  ;
                                 Value       : PChar   ;
                                 Len         : UInt32  ) : LxResult;
    function FirstUnique  (      UniqueIndex : PUInt32 ) : LxResult;
    function Reset                                       : LxResult;
  end;

  ILxScriptQuery = interface
  [LXu_SCRIPTQUERY]
    function Select  (const Attribute, Which : PChar   ) : LxResult;
    function Query   (const Attribute        : PChar   ;
                            Query            : IUnknown) : LxResult;
    function &Type   (const Attribute        : PChar   ;
                            &Type            : PInteger) : LxResult;
    function TypeName(const Attribute        : PChar   ;
                      const Type_            : PPChar  ) : LxResult;
  end;

  ILxStringTag = interface
  [LXu_STRINGTAG]
    function Get    (      &Type : LXtID4;
                     const Tag   : PPChar) : LxResult;
    function &Set   (      &Type : LXtID4;
                     const Tag   : PChar ) : LxResult;
    function Count  (      Count : UInt32) : LxResult;
    function ByIndex(      Index : UInt32;
                           &Type : LXtID4;
                     const Tag   : PPChar) : LxResult;
  end;

  ILxMatrix = interface
  [LXu_MATRIX]
    function Get3          (      Mat3   : LXtMatrix ) : LxResult;
    function Get4          (      Mat4   : LXtMatrix4) : LxResult;
    function GetOffset     (      Offset : LXtVector ) : LxResult;
    function MultiplyVector(const Vector : LXtVector ;
                                  Result : LXtVector ) : LxResult;
    function Set3          (const Mat3   : LXtMatrix ) : LxResult;
    function Set4          (const Mat4   : LXtMatrix4) : LxResult;
    function SetOffset     (const Mat4   : LXtMatrix4) : LxResult;
    function SetIdentity                               : LxResult;
    function Multiply3     (      Mat3   : LXtMatrix ) : LxResult;
    function Multiply4     (      Mat4   : LXtMatrix4) : LxResult;
    function Invert                                    : LxResult;
    function Transpose                                 : LxResult;
  end;

  ILxVisitor = interface
  [LXu_VISITOR]
    function Evaluate : LxResult;
  end;

function LXe_OK_INEXACT_MATCH                 : LxResult;
function LXe_OK_NO_CHOICES                    : LxResult;
function LXe_QUERY_UNKNOWN_SERVICE            : LxResult;
function LXe_QUERY_SERVICE_UNAVAILABLE        : LxResult;
function LXe_QUERY_UNKNOWN_ATTRIBUTE          : LxResult;
function LXe_QUERY_MISMATCHED_TYPE            : LxResult;
function LXe_QUERY_SELECT_FAILED              : LxResult;
function LXe_QUERY_NEED_SELECTION             : LxResult;
function LXe_QUERY_MISMATCHED_SELECTION       : LxResult;
function LXe_QUERY_NOT_APPLICABLE_TO_SELECTED : LxResult;
function LXe_QUERY_ERROR                      : LxResult;

implementation

function LXe_OK_INEXACT_MATCH                 : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_VALUE, 1) // Good, not Fail
end;
function LXe_OK_NO_CHOICES                    : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_VALUE, 2) // Good, not Fail
end;
function LXe_QUERY_UNKNOWN_SERVICE            : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_QUERY, 0);
end;
function LXe_QUERY_SERVICE_UNAVAILABLE        : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_QUERY, 1);
end;
function LXe_QUERY_UNKNOWN_ATTRIBUTE          : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_QUERY, 2);
end;
function LXe_QUERY_MISMATCHED_TYPE            : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_QUERY, 3);
end;
function LXe_QUERY_SELECT_FAILED              : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_QUERY, 4);
end;
function LXe_QUERY_NEED_SELECTION             : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_QUERY, 5);
end;
function LXe_QUERY_MISMATCHED_SELECTION       : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_QUERY, 6);
end;
function LXe_QUERY_NOT_APPLICABLE_TO_SELECTED : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_QUERY, 7);
end;
function LXe_QUERY_ERROR                      : LxResult; inline;
begin
  Result := LXxFAILCODE(LXeSYS_QUERY, 8);
end;

end.

